import inline as inline
import matplotlib
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from pyecharts.charts import Geo
from pyecharts import options as opts
from pyecharts.globals import GeoType
from pyecharts.charts import Map
from scipy import stats
from statsmodels.formula.api import ols
from statsmodels.stats.anova import anova_lm
import warnings
warnings.filterwarnings('ignore')#忽略生成图片时的报错
plt.rcParams['font.sans-serif']='SimHei'
plt.rcParams['axes.unicode_minus']=False#是图片显示中文
# # %matplotlib inline
# %matplotlib inline

data = pd.read_excel(r"beijing.xlsx")
data.head()
data.info()
data.describe().T#转置函数
# def reach_str(data):
#     reaches=[]
#     list=data["reach"].str.findall("\w+").tolist()
#     for i in list:
#         reaches.append(i[0])
#     return reaches

data.reach.value_counts()
data.reach.hist(bins = 30,figsize=(20,8))
plt.show()


def test_geo():
    city = '北京'
    g = Geo()
    g.add_schema(maptype=city, itemstyle_opts=opts.ItemStyleOpts(color="#D9D9D9", border_color="#111"))

    # 定义坐标对应的名称，添加到坐标库中 add_coordinate(name, lng, lat)
    list1 = data['id'].tolist()
    list2 = data.longitude.tolist()
    list3 = data.latitude.tolist()
    for x, y, z in zip(list1, list2, list3):
        g.add_coordinate(str(x), y, z)

    # 将坐标点名称及坐标点值添加到图表中
    b = []
    for i in zip(data['id'].map(str), data['id'].value_counts()):
        b.append(i)
    g.add('', b, type_='scatter', symbol_size=3, color='#68228B')
    # 设置样式成不显示图例
    g.set_series_opts(label_opts=opts.LabelOpts(is_show=False))
    # 设置标题
    g.set_global_opts(
        title_opts=opts.TitleOpts(title="{}-房源分布".format(city))
    )
    return g


g = test_geo()
g.render_notebook()
